package com.doucat.support.component.fragment.host;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import com.doucat.support.component.activity.BaseActivity;
import com.doucat.support.component.start.AbsStarter;
import com.doucat.support.constant.PublicBundleConstant;
import com.tonly.doucatlibrary.R;

/**
 * -----------------------------------------------------------------
 * Copyright (C) 2021-2031, by tonly, All rights reserved.
 * -----------------------------------------------------------------
 * File: HostActivity.java
 * Author: wangfy
 * Create: 2021/7/21 10:19
 * 宿主Activity，用来装载其他的Fragment
 */
public class HostActivity extends BaseActivity {
    Fragment fragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle=getIntent().getBundleExtra(AbsStarter.START_BUNDLE);
        if(bundle!=null){
            try {
                Class aClass= (Class) bundle.getSerializable(PublicBundleConstant.URL);
                fragment= (Fragment) aClass.newInstance();
                fragment.setArguments(bundle);
                replaceFragment(R.id.baseContent,fragment);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        removeFragment(fragment);
    }
}